// pages/my/appointment-recordDetail/appointment-recordDetail.js
const controllers = require('../../controllers/controllerOrder').controller
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsAgreeId: 0,
    accountNick: '',
    failDesc: '',
    state: 0,
    accountMobile: '',
    goodsName: '',
    goodsImage: '',
    sellCount: 0,
    goodsPrice: 0,
    agreeStartTime: '',
    shopAccountName: '',
    shopAccountCall: '',
    desc: '',
    createTime: '',
    imgurl: '',
    vip: 0,
    dialogShow: false,
    buttons: [{
      text: '取消'
    }, {
      text: '确定'
    }],
    inputvalue: '',
    shopName:'',
    detail:''
  },
  //拒绝预约
  reject() {
    this.setData({
      dialogShow: true
    })
  },


  tapDialogButton(e) {
    console.log(e);
    if (e.detail.index == 0) {
      this.setData({
        dialogShow: false
      })
    } else {
      if (this.data.inputvalue == '') {
        wx.showToast({
          title: '请输入拒绝理由',
          icon: 'none'
        })

        return false
      }

      //提交拒绝
      controllers.rejectAppointment({
        failDesc: this.data.inputvalue,
        shopId: wx.getStorageSync('shopId'),
        goodsAgreeId: this.data.goodsAgreeId
      }).then(res => {
        console.log(res);
        wx.showToast({
          title: '已拒绝',
          icon:'none'
        })
        this.setData({
          dialogShow:false
        })
        //获取详情
        controllers.getAppointeRecordDetail({
          shopId: wx.getStorageSync('shopId'),
          goodsAgreeId: this.data.goodsAgreeId
        }).then(res => {
          console.log(res);
          this.setData({
            accountNick: res.data.accountNick,
            accountMobile: res.data.accountMobile,
            failDesc: res.data.failDesc,
            goodsImage: res.data.goodsImage,
            goodsName: res.data.goodsName,
            state: res.data.state,
            vipPrice: res.data.vipPrice,
            goodsPrice: res.data.goodsPrice,
            sellCount: res.data.goods.sellCount,
            agreeStartTime: res.data.agreeStartTime,
            shopAccountCall: res.data.shopAccountCall,
            shopAccountName: res.data.shopAccountName,
            desc: res.data.desc || '',
            createTime: res.data.createTime,
            shopName:res.data.shopName,
            detail:res.data
          })

        })
      })
    }
  },

  //输入拒绝理由
  inputreject(e) {
    this.setData({
      inputvalue: e.detail.value
    })
  },
  //同意预约
  agree() {
    controllers.agreeAppointment({
      shopId: wx.getStorageSync('shopId'),
      goodsAgreeId: this.data.goodsAgreeId
    }).then(res => {
      console.log(res);
      wx.showToast({
        title: '已同意',
        icon:'none'
      })
      //获取详情
      controllers.getAppointeRecordDetail({
        shopId: wx.getStorageSync('shopId'),
        goodsAgreeId: this.data.goodsAgreeId
      }).then(res => {
        console.log(res);
        this.setData({
          accountNick: res.data.accountNick,
          accountMobile: res.data.accountMobile,
          failDesc: res.data.failDesc,
          goodsImage: res.data.goodsImage,
          goodsName: res.data.goodsName,
          state: res.data.state,
          vipPrice: res.data.vipPrice,
          goodsPrice: res.data.goodsPrice,
          sellCount: res.data.goods.sellCount,
          agreeStartTime: res.data.agreeStartTime,
          shopAccountCall: res.data.shopAccountCall,
          shopAccountName: res.data.shopAccountName,
          desc: res.data.desc || '',
          createTime: res.data.createTime,
          shopName:res.data.shopName,
          detail:res.data
        })

      })
    })
  },

  //确认签到
  ok(){
    controllers.comfirmOk({
      shopId:wx.getStorageSync('shopId'),
      goodsAgreeId:this.data.goodsAgreeId
    }).then(res =>{
      console.log(res);
      wx.showToast({
        title: '已签到',
        icon:'none'
      })
      //获取详情
      controllers.getAppointeRecordDetail({
        shopId: wx.getStorageSync('shopId'),
        goodsAgreeId: this.data.goodsAgreeId
      }).then(res => {
        console.log(res);
        this.setData({
          accountNick: res.data.accountNick,
          accountMobile: res.data.accountMobile,
          failDesc: res.data.failDesc,
          goodsImage: res.data.goodsImage,
          goodsName: res.data.goodsName,
          state: res.data.state,
          vipPrice: res.data.vipPrice,
          goodsPrice: res.data.goodsPrice,
          sellCount: res.data.goods.sellCount,
          agreeStartTime: res.data.agreeStartTime,
          shopAccountCall: res.data.shopAccountCall,
          shopAccountName: res.data.shopAccountName,
          desc: res.data.desc || '',
          createTime: res.data.createTime,
          shopName:res.data.shopName
        })

      })
    })
    // let detail=JSON.stringify(this.data.detail)
    // wx.navigateTo({
    //   url: '/pages/settlement/Offline/Offline?detail='+detail,
    // })
  },
  //跳转到线下开单页面
  offline(){
    let detail=JSON.stringify(this.data.detail)
    wx.navigateTo({
      url: '/pages/settlement/Offline/Offline?detail='+detail,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goodsAgreeId: options.id
    })

    this.setData({
      imgurl:app.globalData.IMG_URL
    })

    //获取详情
    controllers.getAppointeRecordDetail({
      shopId: wx.getStorageSync('shopId'),
      goodsAgreeId: this.data.goodsAgreeId
    }).then(res => {
      console.log(res);
      this.setData({
        accountNick: res.data.accountNick,
        accountMobile: res.data.accountMobile,
        failDesc: res.data.failDesc,
        goodsImage: res.data.goodsImage,
        goodsName: res.data.goodsName,
        state: res.data.state,
        vipPrice: res.data.vipPrice,
        goodsPrice: res.data.goodsPrice,
        sellCount: res.data.goods.sellCount,
        agreeStartTime: res.data.agreeStartTime,
        shopAccountCall: res.data.shopAccountCall,
        shopAccountName: res.data.shopAccountName,
        desc: res.data.desc || '',
        createTime: res.data.createTime,
        agreeTime:res.data.agreeTime,
        detail:res.data
      })

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})